<?php

namespace app\company\model;

use app\common\model\BaseModel;
use app\common\model\Dealer;
use think\model\relation\HasMany;
use think\model\relation\HasOne;

class Payment extends BaseModel
{
    protected $deleteTime = false;

    const WAIT = 1;
    const SUCCESS = 2;
    const FAIL = 3;

    const CASH = 1;
    const BANK = 2;

    public function dealer(): HasOne
    {
        return $this->hasOne(Dealer::class, 'id', 'dealer_id');
    }

    public function detail(): HasMany
    {
        return $this->hasMany(PaymentDetail::class, 'payment_id', 'id');
    }

    public function getPayStatusTextAttr($value,$data): string
    {
        $status = [self::WAIT=>'待支付',self::SUCCESS=>'支付成功',self::FAIL=>'支付失败'];
        return $status[$data['pay_status']] ?? '无';
    }

    public function getPayTypeTextAttr($value,$data): string
    {
        $status = [self::CASH=>'现金',self::BANK=>'公司账户'];
        return $status[$data['pay_type']] ?? '无';
    }
}